﻿using DevExpress.Diagram.Core;
using DevExpress.Xpf.Diagram;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QBAnalysis
{
	/// <summary>
	/// Interaction logic for TopologicalGraph.xaml
	/// </summary>
	public partial class TopologicalGraph : UserControl
	{
		public TopologicalGraph()
		{
			InitializeComponent();
			 
			DiagramShape diagramShape = new DiagramShape();
			diagramShape.Height = 100;
			diagramShape.Content = "enen";
			diagramShape.Width = 100;
		
			diagramShape.Shape = BasicShapes.Ellipse;
			myGrid.Items.Add(diagramShape);
		}

		//节点
		public DiagramShape Node(Point point1,int weight)
		{
			DiagramShape diagramShape = new DiagramShape();
			diagramShape.Height = 10* weight;
			diagramShape.Content = "enen";
			diagramShape.Width = 10* weight;
			diagramShape.Position = point1;
			diagramShape.Shape = BasicShapes.Ellipse;
			return diagramShape;
			//diagramControl.Items.Add(diagramShape);
		}

		public Point PortPosition()
		{
			Point point1 = new Point();
			point1.X = 40;
			point1.Y = 60;
			return point1;
		}

		public int r = 20;//连接线的长度

		/// <summary>
		/// 计算点的位置
		/// 返回该点的所有连接点的位置,只有一个连接点的点坐标
		/// </summary>
		public  Dictionary<double, double> PortPosition2(double x, double y, int length)
		{
			Dictionary<double, double> keyValuePairs = new Dictionary<double, double>();

			//循环得出点的坐标
			for (int i = 0; i < length; i++)
			{
				double x1 = (x - r) + r * i / length;
				double y1 = y - Math.Sqrt(r * r - (x - x1) * (x - x1));
				keyValuePairs.Add(x1, y1);
			}
			return keyValuePairs;
		}

		//节之间的线
		public DiagramConnector Line(DiagramShape diagramShape, DiagramShape diagramShape2)
		{
			DiagramConnector diagramConnector = new DiagramConnector();
			diagramConnector.BeginItemPointIndex = 1;
			diagramConnector.BeginItem = diagramShape;
			diagramConnector.EndItem = diagramShape2;
			return diagramConnector;
			//diagramControl.Items.Add(diagramConnector);
		}
	}
}
